package com.zhuss.excecise.processor;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.SearchKeyWordBo;
import com.zhuss.bean.bo.excecise.excecise.SearchExceciseBo;
import com.zhuss.bean.bo.excecise.excecise.wechat.ListExceciseBo;
import com.zhuss.bean.vo.DetailKeyWordVo;
import com.zhuss.bean.vo.excecise.excecise.DetailExceciseVo;
import com.zhuss.bean.vo.excecise.excecise.ListExceciseVo;
import com.zhuss.excecise.db.dao.ext.ExceciseDao;
import com.zhuss.excecise.db.entity.Excecise;
import com.zhuss.common.PageVo;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.exception.WpsException;


/**
 * 查询练习生 processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("exceciseRead")
public class ExceciseRead {
	
	@Autowired
	private ExceciseDao exceciseDao;
	
	/**
	 * 练习生 
	 * @return
	 */
	public Object listExceciseId(Integer area) {
		List<Excecise> exceciseList = exceciseDao.listAll(area);
		List<Long> result = new ArrayList<>();
		transferListId(exceciseList, result);
		return result;
	}
	
	
	/**
	 * keyWord
	 * @param bo
	 * @return
	 */
	public PageVo<DetailKeyWordVo> keyWord(SearchKeyWordBo bo) {
		PageVo<DetailKeyWordVo> result = new PageVo<DetailKeyWordVo>();
		List<DetailKeyWordVo> list = new ArrayList<DetailKeyWordVo>();
		list = exceciseDao.keyWord(bo);
		Integer count = exceciseDao.countKeyWord(bo);
		result.setPageNum(bo.getPageNum());
		result.setPageSize(bo.getPageSize());
		result.setTotal(count);
		result.setItems(list);
		return result;
	}
	
	
	
	/**
	 * 练习生列表
	 * @param bo
	 * @return
	 */
	public Object listExcecise(ListExceciseBo bo) {
		PageVo<DetailExceciseVo> result = new PageVo<DetailExceciseVo>();
		List<DetailExceciseVo> list = new ArrayList<DetailExceciseVo>();
		list = exceciseDao.listExcecise(bo);
		Integer count = exceciseDao.countExceciseList(bo);
		result.setPageNum(bo.getPageNum());
		result.setPageSize(bo.getPageSize());
		result.setTotal(count);
		result.setItems(list);
		return result;
	}
	
	private void transferListId(List<Excecise> exceciseList, List<Long> result) {
		for (Excecise item : exceciseList) {
			result.add(item.getExceciseId());
		}
	}

	/**
	 * 练习生列表
	 * @param bo
	 * @return
	 */
	public Object list(SearchExceciseBo bo) {
		PageVo<ListExceciseVo> result = new PageVo<ListExceciseVo>();
        result.setPageNum(bo.getPageNum());
        result.setPageSize(bo.getPageSize());
        result.setItems(exceciseDao.list(bo));
        result.setTotal(exceciseDao.countList(bo));
		return result;
	}
	
	/**
	 * 练习生详情
	 * @param exceciseId
	 * @return
	 * @throws WpsException
	 */
	public Object detail(Long exceciseId) throws WpsException {
		Object result = exceciseDao.detail(exceciseId);
		if (result == null) {
			throw new WpsException(ExceptionCode.数据不存在);
		}
		return result;
	}
	
	

}
